<?php

namespace app\api\controller;

use app\common\controller\Api;
use app\admin\model\Usermoneylog as UsermoneylogModel;
use think\facade\Db;

/**
 * 首页接口.
 */
class UserMoneyLog extends Api
{
    protected $noNeedLogin = [];
    protected $noNeedRight = ['*'];


    /**
     * 用户充值记录
     * @return void
     */
    public function list(){

        $model = new UsermoneylogModel();
        $list = $model->getList(['user_id'=>$this->auth->id],12,'id,user_id,createtime,oper_type,before_user_level_type,user_level_type,level_day,xieyi_num,after_level_day,after_xieyi_num');

        $userlevellist = Db::name('label')->where('type',1)->select()->toArray();
        $userlevellist = array_column($userlevellist,null,'id');
        foreach($list['data'] as &$vv){

            $before_user_level_type = isset($userlevellist[$vv['before_user_level_type']])?$userlevellist[$vv['before_user_level_type']]['name']:'';
            $user_level_type = isset($userlevellist[$vv['user_level_type']])?$userlevellist[$vv['user_level_type']]['name']:'';

            $operflag = $vv['oper_type']==1?'充值':'退款';
            $operflag2 = $vv['oper_type']==1?'+':'-';
            $vv['content'] = "{$operflag}：{$user_level_type}{$operflag2}{$vv['level_day']}天，协议{$operflag2}{$vv['xieyi_num']}份";
            $vv['after_content'] = "结余：{$user_level_type}{$vv['after_level_day']}天，协议{$vv['after_xieyi_num']}份";
            $vv['createtime'] = date('Y-m-d H:i:s',$vv['createtime']);
        }
        $this->success('成功',$list);
    }
}
